package com.wjqy.controller;

import com.wjqy.entity.*;
import com.wjqy.queryVo.ScenicVo;
import com.wjqy.service.ScenicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
public class ScenicController {

    @Autowired
    private ScenicService scenicService;

    /*@MethodName: showScenic
     * @Author: man
     * @Description: 根据id返回对应的景区信息
     * @Date:  16:27 2020/7/3
     * @Param: [id]
     * @Return: com.wjqy.entity.CommonReturnEntity
    **/
    @RequestMapping(value="scenic",method=RequestMethod.GET)
    public CommonReturnEntity showScenic(int id) {
        ScenicVo scenicVo = null;
        try {
            scenicVo = scenicService.showScenic(id);
        } catch (Exception e) {
            CommonReturnEntity.fail("参数有误！");
        }
        return CommonReturnEntity.success(scenicVo);
    }


    /*@MethodName: showScenic
     * @Author: man
     * @Description: 接收经纬度，返回最近的景区
     * @Date:  16:03 2020/7/3
     * @Param: [x, y]
     * @Return: com.wjqy.entity.CommonReturnEntity
     **/
    @RequestMapping(value = "scenic", method = RequestMethod.POST)
    public CommonReturnEntity showScenic(double x, double y) {
        if (x < -180 || x > 180 || y < -90 || y > 90) {
            return CommonReturnEntity.fail("地标有误");
        }
        Integer id = scenicService.chooseScenic(x, y);
        ScenicVo scenicVo = scenicService.showScenic(id);
        return CommonReturnEntity.success(scenicVo);
    }

    /*@MethodName: allScenic
     * @Author: man
     * @Description: 返回所有景区id和景区名
     * @Date:  16:28 2020/7/3
     * @Param: []
     * @Return: com.wjqy.entity.CommonReturnEntity
    **/
    @RequestMapping(value = "allscenic", method = RequestMethod.GET)
    public CommonReturnEntity allScenicName() {
        List<Local> allScenic = scenicService.findAllScenicLocal();
        return CommonReturnEntity.success(allScenic);
    }

    /*@MethodName: findTicket
     * @Author: man
     * @Description: 查找某个景区下的所有票务信息
     * @Date:  20:49 2020/7/4
     * @Param: [id]
     * @Return: com.wjqy.entity.CommonReturnEntity
    **/
    @RequestMapping("ticket/{id}")
    public CommonReturnEntity findTicket(@PathVariable("id") Integer id){
        List<Ticket> tickets = scenicService.findScenicTicket(id);
        return CommonReturnEntity.success(tickets);
    }


    @RequestMapping("cmt/{id}")
    public CommonReturnEntity showRecommend(@PathVariable("id") Integer id){
        List<Comment> allComment = scenicService.findAllComment(id);
        return CommonReturnEntity.success(allComment);

    }



}
